Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@reach/portal

Package Overview
Dependencies
Maintainers
4
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@reach/portal

Declarative portals for React

  • 0.10.5
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created

What is @reach/portal?

@reach/portal is a React component that allows you to render children into a DOM node that exists outside the DOM hierarchy of the parent component. This is useful for creating modals, tooltips, and other UI elements that need to visually break out of their container.

What are @reach/portal's main functionalities?

Basic Portal Usage

This example demonstrates the basic usage of the @reach/portal package. The `Portal` component is used to render a div outside of the parent DOM hierarchy, which can be useful for creating modals or tooltips.

import React from 'react';
import { Portal } from '@reach/portal';

function App() {
  return (
    <div>
      <h1>My App</h1>
      <Portal>
        <div style={{ position: 'absolute', top: 0, left: 0, background: 'white', border: '1px solid black' }}>
          This is rendered in a portal!
        </div>
      </Portal>
    </div>
  );
}

export default App;

Nested Portals

This example shows how you can nest portals within each other. The nested `Portal` component renders its children outside of the parent DOM hierarchy, allowing for complex UI structures.

import React from 'react';
import { Portal } from '@reach/portal';

function App() {
  return (
    <div>
      <h1>My App</h1>
      <Portal>
        <div style={{ position: 'absolute', top: 0, left: 0, background: 'white', border: '1px solid black' }}>
          This is rendered in a portal!
          <Portal>
            <div style={{ position: 'absolute', top: 20, left: 20, background: 'lightgray', border: '1px solid black' }}>
              This is a nested portal!
            </div>
          </Portal>
        </div>
      </Portal>
    </div>
  );
}

export default App;

Other packages similar to @reach/portal

FAQs

Package last updated on 24 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc